# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Aditya Sirish <aditya@saky.in>

pkgname=procyon-decompiler
pkgver=0.6.0
pkgrel=3
pkgdesc='A Java decompiler, inspired by ILSpy and Mono.Cecil'
arch=('any')
url='https://github.com/mstrobel/procyon'
license=('Apache')
depends=('java-runtime')
makedepends=('git' 'jdk8-openjdk')
_commit='05ff703eafbbbc6afa0484946f5a3f2c83d773bb'
source=(
  "$pkgname::git+$url#commit=$_commit"
  'wrapper.sh'
  'gradle-repro.patch'
)
b2sums=('SKIP'
        '5dc6e2054663ebb967729ea916b566f1f84bca1e2f17146b7833b12c21cb66853769dd27d589869ccf38ce6633a66d856515486e7cba9ae5d8aa6e3ab305b397'
        '51fe976ff80bb20f4363b3a5ee0f4ee1336dad63f1b3c38a9a337bf203a67694867527cda5f77027cad71643fa2f6af9d4786bbf87e5c76aa13d770a757de0dd')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  patch -p1 -i "$srcdir/gradle-repro.patch"
}

build() {
  cd "$pkgname"

  # Force the system to build the package using JDK 8
  export PATH="/usr/lib/jvm/java-8-openjdk/bin/:$PATH"
  export JAVA_HOME="/usr/lib/jvm/java-8-openjdk"

  ./gradlew Procyon.Decompiler:build
}

package() {
  cd "$pkgname"

  # wrapper
  install -vDm755 "$srcdir/wrapper.sh" "$pkgdir/usr/bin/$pkgname"

  # jar
  install -vDm644 "build/Procyon.Decompiler/libs/$pkgname-$pkgver.jar" "$pkgdir/usr/share/java/$pkgname/$pkgname.jar"
}
